package controller

import (
	"fmt"
	"net/http"
	"strings"
)

type gateway struct {
	v2 http.Handler
	v3 http.Handler
}

func (g *gateway) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	fmt.Printf("r.URL.Path: %v\n", r.URL.Path)
	if strings.HasPrefix(r.URL.Path, "/api/") {
		fmt.Printf("r.URL.Path2: %v\n", r.URL.Path)
		g.v2.ServeHTTP(w, r)
		return
	}
	g.v3.ServeHTTP(w, r)
}

func Start(addr string) {
	gate := &gateway{
		v2: New_V2Handlers(),
		v3: New_V3Handlers(),
	}

	// addr := fmt.Sprintf(":%d", settings.SitePort)
	srv := &http.Server{
		Addr:    addr,
		Handler: gate,
	}

	srv.ListenAndServe()
}
